﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using System.Data;
using System.Data.Common;
using System.Data.SqlClient;

using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;

using DAL;
using BO;

namespace BLL
{
    public class AdMagnager
    {
        AdDB db = null;
        DataSet ds = null;

        public AdMagnager()
        {
            db = new AdDB();
        }

        #region "Public Method"

        public IDataReader SelectAdCategoryMaster()
        {
            IDataReader rd;
            rd = db.Select_AdCategoryMaster();
            return rd;
        }

        public int InsertAdMaster(BO.Ad bo)
        {
            int Result = 0;
            Result = db.Insert_AdMaster(bo.UserID, bo.AdCategoryID, bo.SubCategoryID, bo.AdTitle, bo.ImagePath, bo.ProductDescription, bo.LandMark, bo.State, bo.Country, bo.FeaturedAd, bo.TopAd, bo.HomepageGallery);
            return Result;
        }

        public int UpdateAdMaster(BO.Ad bo)
        {
            int Result = 0;
            Result = db.Update_AdMaster(bo.UserID, bo.AdCategoryID, bo.SubCategoryID, bo.AdTitle, bo.ImagePath, bo.ProductDescription, bo.LandMark, bo.State, bo.Country, bo.AdID);
            return Result;
        }

        public IDataReader SelectLatestTopFeaturedAd(BO.Ad bo)
        {
            IDataReader rd;
            rd = db.Select_LatestTopFeaturedAd(bo.TypeID, bo.Country);
            return rd;
        }
         
        public DataSet Select_RelatedAds(BO.Ad bo)
        {
            ds = new DataSet();
            ds = db.Select_RelatedAds(bo.AdID);
            return ds;
        }

        public DataSet Select_AdImageVideos(BO.Ad bo)
        {
            ds = new DataSet();
            ds = db.Select_AdImageVideos(bo.AdID);
            return ds;
        }

        public DataSet Deactivate_AdImageVideos(BO.Ad bo)
        {
            ds = new DataSet();
            ds = db.Deactivate_AdImageVideos(bo.AdImageVideosID);
            return ds;
        }

        public DataSet Update_Image(BO.Ad bo)
        {
            ds = new DataSet();
            ds = db.Update_Image(bo.AdImageVideosID, bo.Path);
            return ds;
        }

        public DataSet BindSubCategoryMasterDetails(BO.Ad bo)
        {
            ds = new DataSet();
            ds = db.Select_SubCategoryMasterDetails(bo.CategoryID);
            return ds;
        }

        public DataSet Select_AllSubCategoryAds()
        {
            ds = new DataSet();
            ds = db.Select_AllSubCategoryAds();
            return ds;
        }

        public IDataReader ShowSubCategoryMasterDetails(BO.Ad bo)
        {
            IDataReader rd;
            rd = db.Bind_SubCategoryMasterDetails(bo.AdCategoryID);
            return rd;
        }

        public DataSet BindAdCategoryMaster()
        {
            ds = new DataSet();
            ds = db.Bind_AdCategoryMaster();
            return ds;
        }

        public DataSet SelectAdPostedClientDetails(BO.Ad bo)
        {
            ds = new DataSet();
            ds = db.Select_AdPostedClientDetails(bo.AdID);
            return ds;
        }

        public string InsertContactDealerDetails(BO.Ad bo)
        {
            string Result = string.Empty;
            Result = db.Insert_ContactDealerDetails(bo.UserID, bo.FName, bo.Email, bo.Message,bo.AdID);
            return Result;
        }

        public DataSet SelectMembershipType(BO.Ad bo)
        {
            ds = new DataSet();
            ds = db.Select_MembershipType(bo.ItemID);
            return ds;
        }

        public IDataReader InsertPaymentMaster(BO.Ad bo)
        {
            IDataReader rd;
            rd = db.Insert_PaymentMaster(bo.UserID, bo.ItemID, bo.NetPayable, bo.UserName, bo.Email, bo.Currency, bo.Phone, bo.Purpose);
            return rd;
        }

   

        public IDataReader SelectLocationMaster()
        {
            IDataReader rd;
            rd = db.Select_LocationMaster();
            return rd;
        }

        public DataSet SelectAdvancedSearch(BO.Ad bo)
        {
            ds = new DataSet();
            ds = db.Select_AdvancedSearch(bo.AdTitle, bo.CategoryID, bo.SubCategoryID, bo.LandMark,  bo.ColumnName, bo.SearchValue);
            return ds;
        }

        public DataSet Select_UserAds(BO.Ad bo)
        {
            ds = new DataSet();
            ds = db.Select_UserAds(bo.UserID);
            return ds;
        }

   
        public bool CheckAd_IsPostedByUser(BO.Ad bo)
        {
            return db.CheckAd_IsPostedByUser(bo.AdID, bo.UserID);
        }

        public void Insert_AdImageVideosPath(BO.Ad bo)
        {
            db.Insert_AdImageVideosPath(bo.AdID, bo.Path, bo.IsImage, bo.IsVideo);
        }

        public void Delete_AllVideos(BO.Ad bo)
        {
            db.Delete_AllVideos(bo.AdID, bo.IsVideo);
        }

        public string DeletePaymentMaster(BO.Ad bo)
        {
            string Result = string.Empty;
            Result = db.Delete_PaymentMaster(bo.PaymentID);
            return Result;
        }

        public string UpdatePaymentMaster(BO.Ad bo)
        {
            string Result = string.Empty;
            Result = db.Update_PaymentMaster(bo.PaymentID, bo.TransactionID, bo.PaymentStatus);
            return Result;
        }

       

        public IDataReader SelectCountryMaster()
        {
            IDataReader rd;
            rd = db.Select_CountryMaster();
            return rd;
        }

        public IDataReader SelectAdLocation_AdID(BO.Ad bo)
        {
            IDataReader rd;
            rd = db.Select_AdLocation_AdID(bo.AdID);
            return rd;
        }

        public IDataReader SelectRightAd(BO.Ad bo)
        {
            IDataReader rd;
            rd = db.Select_RightAd(bo.CountryID);
            return rd;
        }

        #endregion
    }
}